<%@include file="connect.jsp" %>
<%
    String para = request.getParameter("para");
    String id = request.getParameter("learnId");
    String ganti = para.replaceAll("'", "''");

    String sql = "select * from DetailLearn where learnID='" + id + "'";
    Integer flag = 0;
    ResultSet rs = stat.executeQuery(sql);
    while (rs.next()) {
            String words = rs.getString("words").toString();
        int st = para.indexOf(words + " ");
        int a =  para.indexOf(words + ".");
        System.out.println(st);
        System.out.println(a);
        if (para.indexOf(words + " ") < 0 && para.indexOf(words + ".") < 0 && para.indexOf(words + ",")<0 ) {
            flag = 1;

        }
    }
    if (flag == 1) {
        response.sendRedirect("EditLearn.jsp?respon=ERROR! The paragraph doesn't contains the words that shown on the table&id="+ id);

    } else {
        stat.executeUpdate("UPDATE Learn SET Paragraph = '" + ganti + "' where learnID = '" + id + "' ");

        response.sendRedirect("EditLearn.jsp?respon=Successfully updated paragraph&id=" + id);

    }
    conn.close();
%>